home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_mc.idb / usr / freeware / lib / mc / extfs / cpio.z / cpio
Encoding:
Text File  |  1998-10-28  |  1.1 KB  |  74 lines

  1. #!/bin/sh
  2. #
  3. # Written by Stas Maximov 1998 SVR4 (UnixWare)
  4. # stmax@u213.srcc.msu.su 
  5. # (C) 1996 The Free Software Foundation.
  6. #
  7. #
  8.  
  9. uni_cat ()
  10. # $1 is the archive name
  11. {
  12.     case "$1" in
  13.     *.cpio.Z)    compress -dc "$1"
  14.     ;;
  15.     *.cpio.gz)    gzip -dc "$1"
  16.     ;;
  17.     *.cpio)    cat "$1"
  18.     ;;
  19.     *)        echo "unknown extension"
  20.     esac
  21. }
  22.  
  23. mccpiofs_list ()
  24. # $1 is the archive name
  25. {
  26.     uni_cat "$1" | cpio -itv | /bin/awk '
  27.     {
  28.         if (substr($9,length($9),1) == ",")
  29.         {
  30.         tmp = substr($9, 1, length($9)-1);
  31.         $9 = $8;
  32.         $8 = tmp
  33.         }
  34.         else if (substr($10,length($10),1) == ",")
  35.         {
  36.         tmp = substr($10, 1, length($10)-1);
  37.         $10 = $9
  38.         $9 = tmp 
  39.         }
  40.         
  41.         print $0
  42.     }'
  43. }
  44.  
  45. mccpiofs_copyout ()
  46. # $1 is the archive name
  47. # $2 is a name of a file within the archive
  48. # $3 is a name of a file within the system (to add from or extract to)
  49. {
  50.     TMPDIR=/tmp/mctmpdir.$$
  51.     mkdir $TMPDIR
  52.     cd $TMPDIR
  53.     uni_cat "$1" | cpio -icumd "$2" 2>/dev/null
  54.     mv "$2" "$3"
  55.     cd /
  56.     rm -rf $TMPDIR
  57. }
  58.  
  59. #
  60. # main
  61. #
  62.  
  63.     case "$1" in
  64.     list)   mccpiofs_list $2
  65.         exit 0
  66.         ;;
  67.     copyout) mccpiofs_copyout $2 $3 $4
  68.         exit 0
  69.         ;;
  70.     esac
  71.  
  72.     exit 1
  73.  
  74.